package com.xuan.webfinally.mapper;

import com.xuan.webfinally.entity.LastestWeather;
import com.xuan.webfinally.entity.SlopeWeatherData;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuan.webfinally.entity.pax6;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 气象监测数据表 Mapper 接口
 * </p>
 *
 * @author gyuxuan
 * @since 2025-05-18
 */
@Mapper
public interface SlopeWeatherDataMapper extends BaseMapper<SlopeWeatherData> {

    @Select("SELECT temperature,humidity,wind_speed,pressure FROM slope_weather_data ORDER BY create_time DESC LIMIT 1")
    LastestWeather getLatestSlopeInfo();

    @Select("SELECT humidity FROM slope_weather_data ORDER BY create_time DESC LIMIT 1")
    Double getHumidity();


    @Select("SELECT temperature FROM slope_weather_data ORDER BY create_time DESC LIMIT 1")
    Double getTemperature();



    @Select("SELECT daily_rainfall FROM slope_weather_data ORDER BY create_time DESC LIMIT 1")
    Double getRainfall();

    @Select("SELECT device_sn, monitor_id,cumulative_rainfall, daily_rainfall, " +
            "hourly_rainfall, min_rainfall, temperature, pressure, " +
            "wind_speed, wind_direction, humidity, solar_radiation, " +
            "create_time, update_time " +
            "FROM (" +
            "    SELECT *, " +
            "    ROW_NUMBER() OVER (PARTITION BY device_sn ORDER BY create_time DESC) AS rn " +
            "    FROM slope_weather_data " +
            "    WHERE slope_id = #{deptId} " +
            ") t " +
            "WHERE rn = 1")
    List<pax6> selectWeatherDataList(String deptId);
}
